var a = require("../../utils/config.js");

Page({
    data: {
        userName: "",
        idCard: "",
        address: "",
        sex: "",
        idCardZImage: "",
        idCardFImage: ""
    },
    onLoad: function(a) {
        this.setData({
            userName: a.userName,
            idCard: a.idCard,
            address: a.address,
            sex: a.sex,
            idCardZImage: a.idCardZImage
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    chooseIdCardZImage: function() {
        var a = this;
        wx.showModal({
            title: "系统提示",
            content: "请将手机横向拍摄",
            success: function(e) {
                e.confirm && wx.chooseImage({
                    count: 1,
                    success: function(e) {
                        a.setData({
                            idCardZImage: e.tempFilePaths[0]
                        });
                    }
                });
            }
        });
    },
    chooseIdCardFImage: function() {
        var a = this;
        wx.showModal({
            title: "系统提示",
            content: "请将手机横向拍摄，尽量将身份证填满框内",
            success: function(e) {
                e.confirm && wx.chooseImage({
                    count: 1,
                    success: function(e) {
                        a.setData({
                            idCardFImage: e.tempFilePaths[0]
                        });
                    }
                });
            }
        });
    },
    apply: function() {
        var e = this;
        if (e.data.idCardZImage) if (e.data.idCardFImage) {
            wx.showLoading({
                mask: !0
            });
            var t = {
                userId: wx.getStorageSync("userId"),
                userName: e.data.userName,
                idCard: e.data.idCard,
                idCardZImage: wx.getFileSystemManager().readFileSync(e.data.idCardZImage, "base64"),
                idCardFImage: wx.getFileSystemManager().readFileSync(e.data.idCardFImage, "base64"),
                address: e.data.address,
                sex: e.data.sex
            };
            wx.request({
                url: a.urlList.API_USER_AUTHENTICATION,
                method: "POST",
                header: {
                    contentType: "application/json"
                },
                data: t,
                success: function(a) {
                    wx.hideLoading(), 200 == a.data.status ? (wx.navigateBack({
                        delta: 2
                    }), wx.showToast({
                        title: "实名认证成功"
                    })) : wx.showModal({
                        title: "系统提示",
                        content: a.data.message,
                        showCancel: !1,
                        confirmText: "我知道了"
                    });
                }
            });
        } else wx.showToast({
            title: "请上传身份证照反面照片",
            icon: "none"
        }); else wx.showToast({
            title: "请上传身份证照正面照片",
            icon: "none"
        });
    }
});